import sys
import os
import random
import time
BASE_PATH = os.path.dirname(
    os.path.dirname(os.path.abspath(__file__))
)
sys.path.insert(0,BASE_PATH)

from bin import get_Webdriver
from page_object.public import Public


class Marks_Manage:
    """标记管理"""
    def __init__(self):
        self.driver = get_Webdriver.Get_Webdriver().driver

    def jumptoMarkspage(self):
        curl = Public().getCurrentUrl()
        if '/mark/main.html' not in curl:
            self.driver.click("link_text=>数据分析工具")
            self.driver.click("link_text=>标记管理")
        else:
            time.sleep(1)
            self.driver.F5()

    def clickAddMakrsButton(self):
        """点击添加标记按钮"""
        self.driver.click("css=>.icon-plus")
        self.driver.click("css=>.task-info")

    def clickSystemMarks(self):
        """点击系统标记"""
        self.driver.click("link_text=>系统标记")

    def clickMarksList(self):
        """点击标记列表"""
        self.driver.click("link_text=>标记列表")

    def typeMarkName(self, name=''):
        """输入标记名称"""
        self.driver.clear("css=>#name")
        self.driver.type("css=>#name", name)

    def typeMarkContent(self, content=''):
        """输入标记内容"""
        self.driver.clear("css=>#content")
        self.driver.type("css=>#content", content)

    def clickSaveButton(self):
        """点击保存按钮"""
        self.driver.click("css=>#savebtn")

    def clickDeleteButton(self):
        """点击删除按钮"""
        self.driver.click("css=>a[onclick = 'del()']")

    def getMarklistIds(self):
        """获取标记列表下所有标记id"""
        id_list = self.driver.get_attributes("css=>#treeDemo_185_ul>li", "id")
        return id_list

    def getMarklistid(self):
        """获取标记列表的id"""
        fullid = self.driver.get_attribute("css=>a[title='标记列表']", "id")
        marktopid = fullid.split("_")[1]
        return marktopid

    def clickMarklistByid(self, markid):
        """通过id点击标记列表中的标记"""
        marktopid = self.getMarklistid()
        self.driver.click("css=>#treeDemo_{}_ul>#{}".format(marktopid, markid))

    def getSaveMarkInfo(self):
        """获取保存的标记内容"""
        name_script = "return $('#name').val();"
        content_script = "return $('#content').val();"
        name_value = self.driver.js_getvalue(name_script)
        content_value = self.driver.js_getvalue(content_script)
        info = [name_value, content_value]
        return info



if __name__ == '__main__':
  pass